<template>
<!--index.wxml-->

  <view class="container">
    <view class="swiper-box">
      <view class="nickname-box">
        <view class="nickname">
         
          <view style="margin-bottom:30px;">您有{{num}}个</view>
          <view>待支付订单</view>
        </view>
      </view>
      <image src="https://shops.cg500.com/static/aijiu/bg@2x.png" class="backimg"></image>
     
    </view>
    <view class="list-mine">
      <scroll-view scroll-y="true" style="height: 435px;">
        <view v-for="(item, index) in list" :key="index" class="list-cell">
          <view>
            <view style="margin-bottom:3px;font-size:14px;">{{item.address}}</view>
            <view style="font-size:13px;color:#999999">{{item.date}}</view>
          </view>
          <view style="color:#CB3C3C;font-size:16px;">￥{{item.total_price}}元</view>
        </view>
        
      </scroll-view>
      
    </view>
    <view class="btn-box">
      <button style="width: 320px;" class="btn" @tap="pay_all">一键支付所有订单</button>
      </view>
  </view>
</template>

<script>
//index.js
const app = getApp().globalData;
import iCell from "../../components/yhzcell/mycell";

export default {
  data() {
    return {
      list: "",
      num: ""
    };
  },

  components: {
    iCell
  },
  props: {},
  onLoad: function () {
    this.getorder();
  },
  methods: {
    //获取订单信息
    getorder: function () {
      var _this = this;
	  let user_id = uni.getStorageSync('userInfo') ?uni.getStorageSync('userInfo').user_id : ''
      uni.request({
        url: app.post_url + '/api/v1/select_order',
        //仅为示例，并非真实的接口地址
        data: {
          user_id: user_id,
          status: 0
        },
        method: 'post',

        success(res) {

          _this.setData({
            list: res.data.data.data,
            num: res.data.data.data.length
          });

          console.log(_this.list);
        }

      });
    },
    pay_all: function () {
      var _this = this;
	  console.log(app,'app1')
	  let user_id = uni.getStorageSync('userInfo') ?uni.getStorageSync('userInfo').user_id : ''
      uni.request({
        url: 'https://yhzzf.axu9.com/api/v1.order/pay',
        //仅为示例，并非真实的接口地址
        data: {
          user_id: user_id,
          status: 0
        },
        method: 'post',

        success(res) {
          uni.requestPayment({
            timeStamp: res.data.data.payInfo.timeStamp,
            nonceStr: res.data.data.payInfo.nonceStr,
            package: res.data.data.payInfo.package,
            signType: 'MD5',
            paySign: res.data.data.payInfo.paySign,

            success(res) {},

            fail(res) {}

          });
        }
      });
    }
	// pay_all: function () {
	//   var _this = this;
	//   uni.request({
	//     url: app.post_url + 'api/wechat/wechatpay',
	//     //仅为示例，并非真实的接口地址
	//     data: {
	//       user_id: app.user_info.user_id,
	//       status: 0
	//     },
	//     method: 'post',
	
	//     success(res) {
	//       console.log(res);
	//       uni.requestPayment({
	//        timeStamp: res.data.timeStamp,
	//        nonceStr: res.data.nonceStr,
	//        package: res.data.package,
	//        signType: 'MD5',
	//        paySign: res.data.paySign,
	
	//         success(res) {},
	
	//         fail(res) {}
	
	//       });
	//     }
	//   });
	// }
	
  }
};
</script>
<style>
@import "./index.css";
</style>